#encoding=utf8
'''
Created on 2012-10-18

@author: Administrator
'''
from dispatch.Processor import Processor
from pub import Func, UserDict, RoomDict;
from pub.Config import Config

class RIUEClass(Processor):
    '''
    指令：RIUE(room idiom user exit) 
    备注：玩家放弃接龙
    格式：c-s:cmd#cmdID#roomId#userId
     s-c:cmd#cmdId#roomId#userId#userNickName
    
    '''
    def __init__(self,):
        Processor.__init__(self,)
        self.__roomId = 0;
        self.__userId = 0;
        
    def dataValidtor(self, cmdContent):
        if not cmdContent:
            return False;
        paraLen = len(cmdContent);
        if paraLen == 2:      
            self.__roomId = Func.strToInt(cmdContent[0], Config.I_SYS_ZERO);
            self.__userId = Func.strToInt(cmdContent[1], Config.I_SYS_ZERO);                 
            return True;        
        return False;
    def outData(self,):
        room = RoomDict.getRoomFromDictById(self.__roomId);
        if not room:
            return False;
        user = RoomDict.findUserInRoom(self.__userId);
        if not user:
            return False;
        user.set_user_state(Config.I_USER_GAME_STATE_OVER);
        nickName = user.get_user_nick_name();
        sendStr = self.setPackage([self.__roomId, self.__userId, nickName]);
        RoomDict.sendInfoToRoomAllUser(roomObj=room, cmd="", msg=sendStr, isPackage=False);        
        return True;
        
